home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / mkdir.c < prev    next >
C/C++ Source or Header  |  1993-10-11  |  946b  |  50 lines

  1. /* mkdir: make a new directory
  2.  * written by Eric R. Smith and placed in the public domain
  3.  * modified by Alan Hourihane, to check for directory and return EEXIST.
  4.  */
  5.  
  6. #include <errno.h>
  7. #include <limits.h>
  8. #include <osbind.h>
  9. #include <mintbind.h>
  10. #include <types.h>
  11. #include <stat.h>
  12. #include <unistd.h>
  13. #include "lib.h"
  14.  
  15. extern int errno;
  16. extern int __mint;
  17.  
  18. int mkdir(_path, mode)
  19.     const char *_path;
  20.     mode_t mode;
  21. {
  22.     struct stat statbuf;
  23.     int rv;
  24.     char path[PATH_MAX];
  25.  
  26.     _unx2dos(_path, path);
  27.  
  28.     rv = stat(path, &statbuf);    /* Stat directory */
  29.     if (rv == 0) {            /* Does it exist ? */
  30.         errno = EEXIST;        /* Yes, so tell user. */
  31.         return -1;
  32.     }
  33.  
  34.     if (errno != ENOENT) {        /* Return stat error, if other than */
  35.         return -1;        /* File not found. */
  36.     }
  37.  
  38.     rv = Dcreate(path);
  39.     if (rv < 0) {
  40.         errno = -rv;
  41.         return -1;
  42.     }
  43.     if (__mint >= 9) {
  44.         int umask = Pumask (0);
  45.         (void) Pumask (umask);
  46.         (void)Fchmod(path, mode & ~umask);
  47.     }
  48.     return 0;
  49. }
  50.